import { createWebHistory, createRouter } from 'vue-router'

const routes = [{
    path: '/:pathMatch(.*)*',
    name: 'NotFound',
    component: () => import('./Page/404.vue'),
    hidden: true
}, {
    path: '/',
    name: 'index',
    component: () => import('./Page/List.vue'),
}, {
    path: '/Edit/:id',
    name: 'Edit',
    component: () => import('./Page/Edit.vue'),
}, {
    path: '/Content',
    name: 'Content',
    component: () => import('./component/Content/Content.vue'),
}]

const router = createRouter({
    history: createWebHistory(),
    routes,
})

router.beforeEach((to, from, next) => {
    // 检查是否从/html重定向
    if (from.path === '/index.html') {
        // 构造新的路径，包括查询参数
        const newPath = `/?${new URLSearchParams(from.query).toString()}`;
        // 重定向到新的路径
        next(newPath);
    } else {
        // 对于其他情况，正常继续
        next();
    }
});


export { router }